<?php
/**
 *	@author wyl
 *	@date 2015-8-19 09:33:44
 */
class CronjobLog{
	public $rootPath;
	public $logPath;
	public $namespace;
	public $pathFormat;
	public $filename;
	
	public function __construct(){
		$this->init();
	}
	
	public function reset(){
		$this->logPath=$this->rootPath;
		return $this;
	}
	
	public function init(){
		$this->rootPath=Yii::app()->basePath.'/log/cronjob';
		$this->logPath=$this->rootPath;
	}
	
	public function addDir($dirName){
		$path=$this->logPath.'/'.$dirName;
		if(!file_exists($path)){
			mkdir($path,0777,true);
		}
		$this->logPath=$path;
		return $this;
	}
	
	public function logFile($fileName){
		$this->filename=$fileName;
		return $this;
	}
	public function setNamespace($namesapce){
		if(empty($this->filename)){
			$this->filename=$namesapce;
		}
		$this->namespace = $namesapce;
	}
	
	public function addLog($action,$info){
		$logInfo='['.date('Y:m:d h:i:s').'--'.$action.']'.$info."\n";
		file_put_contents($this->logPath.'/'.$this->filename.'.log',$logInfo,FILE_APPEND);
	}
	
}